home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / utility / 541 / mdformat / mdformat.s < prev    next >
Encoding:
Text File  |  1985-11-19  |  50.7 KB  |  1,285 lines

  1. ;*********************************************************************
  2. ;*      MDFORMAT.PRG  (short for "Musical Disk Formatter v1.0")      *
  3. ;*                    and TUTORIAL SOURCE CODE                       *
  4. ;*           was written by Clark A. Hay on July 17, 1991.           *
  5. ;*               - for Color Monitor Only - Med Rez. -               *
  6. ;* Plays some music while you format your disk with 10 sectors/track!*
  7. ;* Does NOT use sector skewing as with "TWISTER" and others like it. *
  8. ;*                                                                   *
  9. ;* If you are a programmer, this source code should be fairly easy to*
  10. ;* modify so that it could be used in any resolution by adjusting the*
  11. ;* the cols and rows, the fill colors, and fonts based on user res.  *
  12. ;*                                                                   *
  13. ;*   For the less ambitious programmer, this code contains several   *
  14. ;*              routines which you may find of interest:             *
  15. ;*                                                                   *
  16. ;* 1. You can learn how a disk is formatted in 5 easy steps:         *
  17. ;*    a. format all tracks on sides 1 and 2 using XBIOS #10          *
  18. ;*    b. 0 out the 1st 2 tracks on each side for the FAT and DIR's   *
  19. ;*    c. use XBIOS #18 to create a protoboot sector                  *
  20. ;*    d. modify the buffer if using more than 9 sectors per track.   *
  21. ;*    e. write boot sector buffer to disk at sector 1 track 0 side 0.*
  22. ;*                                                                   *
  23. ;* 2. Learn how to use a few key Line_A calls such as:               *
  24. ;*    a. DrawLine - to make a line anywhere on the screen.           *
  25. ;*    b. BoxFill  - to make different types of filled boxes          *
  26. ;*    c. TextBlit - to put strings of various sizes/styles anywhere  *
  27. ;*    d. Change Mouse - modify the mouse shape and color as desired  *
  28. ;*                                                                   *
  29. ;* 3. Discover how ongoing music can be produced and controlled.     *
  30. ;*    (admittedly, the music here is no big treat - add your own!)   *
  31. ;*                                                                   *
  32. ;*                             EXPERIMENT                            *
  33. ;*  Feel free to modify the code, steal it, use it, or play with it. *
  34. ;*                          - Clark A. Hay -                         *
  35. ;*********************************************************************
  36.  
  37. ; Offsets into data tables of variables used by my Line_A routines
  38. BOX_X1       EQU 0              ;box fill upper left col
  39. BOX_Y1       EQU 2              ;box fill upper left row
  40. BOX_X2       EQU 4              ;box fill lower right col
  41. BOX_Y2       EQU 6              ;box fill lower right row
  42. BOXFCOLR     EQU 8              ;color to fill the box with
  43. BOXFFILL     EQU 10             ;addr of the fill pattern
  44. BOXFMODE     EQU 14             ;writing mode for the fill pattern
  45.  
  46. BOXLCOLR     EQU 16             ;colour of the line surrounding box
  47. BOXLPTRN     EQU 18             ;pattern of the line     "       "
  48. BOXLMODE     EQU 20             ;writing mode for the line
  49.  
  50. ; the four Line_A writing modes:
  51. REPLACE      EQU 0              ;does what it says - overwrites
  52. JUST_OR      EQU 1              ;adds color bits to the screen color
  53. MAKE_EOR     EQU 2              ;reverses screen color
  54. INVRT_OR     EQU 3              ;similar to above and then OR's line
  55.  
  56. ;---------------------------------------------------------------------
  57. CALCPROG: ;set the stack we use and calculate the size of our program
  58.     MOVE.L   A7,A1              ; get current addr
  59.     PEA      PRGSTACK           ; put in our program stack
  60.     MOVE.L   4(A1),A1           ; get addr of basepage info
  61.     MOVE.L   $C(A1),D0          ; get program text length
  62.     ADD.L    $14(A1),D0         ; add program data length
  63.     ADD.L    $1C(A1),D0         ; add program bss  length
  64.     ADD.L    #$100,D0           ; add room for 256 byte basepage
  65.  
  66. SET_BLOCK: ;reserve only the space needed for our program:
  67.     MOVE.L   D0,-(SP)           ;reserve this number of bytes
  68.     MOVE.L   A1,-(SP)           ;starting at this address
  69.     CLR.W    -(SP)
  70.     MOVE.W   #$4A,-(SP)
  71.     TRAP     #1
  72.     LEA      12(SP),SP
  73.     TST.L    D0                 ;did setblock fail?
  74.     BMI      BYE_BYE            ;if so, we bail out quick
  75.  
  76.     BSR      GET_REZ
  77.     CMP.W    #1,D0              ;are we in medium rez?
  78.     BNE      BYE_BYE            ;if not, get out
  79.  
  80.     BSR      INITLN_A           ;gets addresses we'll need for Line_A
  81.     BSR      MOUS_OFF           ;hide the mouse cursor
  82.  
  83.     LEA      MOUSE_1,A0         ;select the shape we'll use for it
  84.     BSR      CHNGMOUS           ;make the mouse that shape and color
  85.  
  86.     BSR      DO_BOXES           ;draw all boxes & set our write modes
  87.     BSR      DO_TEXT            ;put the text in the boxes
  88.  
  89.     BSR      DEFAULTS           ;set the default boxes and variables
  90.     BSR      MOUS_ON            ;and show the mouse again
  91.  
  92.     CLR.W    EXITFLAG           ;make sure our exit flag is false (0)
  93.  
  94. MAINLOOP: ;here we go...
  95.     TST.W    EXITFLAG           ;does the user want to quit?
  96.     BNE      BYE_BYE            ;if not 0, then yes - so leave
  97.     BSR      E_MULT             ;get a keyboard or mouse response
  98.     TST.L    D0                 ;did user press a key?
  99.     BEQ      NO_KEY             ;if not, then user pressed mouse
  100.     CMP.B    #13,D0             ;did user press the return key?
  101.     BNE      NOT_RTN            ;if not then skip the format
  102.     BSR      DOFORMAT           ;else format the disk
  103.     BSR      CLR_KBD            ;get rid of key-presses during format
  104.     BRA      MAINLOOP           ;and go back for more
  105. NOT_RTN:
  106.     CMP.B    #27,D0             ;did user press the escape key?
  107.     BEQ      BYE_BYE            ;if so, we leave
  108.     BRA      MAINLOOP           ;else go back and try again
  109. NO_KEY:  ;user pressed a mouse button
  110.     CMP.W    #1,D1              ;did user press the left mouse button?
  111.     BNE      MAINLOOP           ;if not,then ignore it.
  112.     BSR      CHKBOXES           ;else check the boxes and do routine
  113.     BRA      MAINLOOP           ;and go back for more
  114.  
  115. BYE_BYE: ;we prepare to leave:
  116.     BSR      MOUS_OFF           ;hide the mouse
  117.     BSR      CLR_SCRN           ;clear the screen
  118.     BSR      CLR_KBD            ;clear the keyboard buffer
  119.     BSR      CLR_MOUS           ;clear the mouse buttons
  120.     BSR      MOUS_ON            ;turn mouse back on
  121.     CLR.W    -(SP)              ;and leave this program
  122.     TRAP     #1
  123. ;*********************************************************************
  124. ;*     here are all the sub-routines I employ in this program:       *
  125. ;*********************************************************************
  126. INITLN_A:
  127.     MOVEM.L  D0-D3/A0-A3,-(SP)
  128.     DC.W     $A000              ;gets us some important Line_A addrs
  129.     MOVE.L   A0,LN_AVARS        ;save addr of all Line_A variables
  130.     MOVE.L   A1,LN_AFONT        ;save addr of font table pointer
  131.     MOVEM.L  (SP)+,D0-D3/A0-A3
  132.     RTS
  133. ;---------------------------------------------------------------------
  134. CHNGMOUS: ;addr of new mouse data & shape should be in A0
  135.     MOVEM.L  D0-D7/A0-A6,-(SP)
  136.     MOVE.L   LN_AVARS,A1
  137.     MOVE.L   8(A1),A1           ;get Line_A IntIn array
  138.     MOVE.L   (A0)+,(A1)+        ;set col and row of new mouse hot spot
  139.     ADDQ.L   #2,A1
  140.     MOVE.L   (A0)+,(A1)+        ;set the mask and mouse colors
  141.     MOVE.W   #15,D0             ;16 long words of mouse shape data
  142. CHGMOUS:
  143.     MOVE.L   (A0)+,(A1)+        ;transfer mouse data
  144.     DBRA     D0,CHGMOUS         ;till done
  145.     DC.W     $A00B              ;change to our new mouse shape!
  146.     MOVEM.L  (SP)+,D0-D7/A0-A6
  147.     RTS
  148. ;---------------------------------------------------------------------
  149. DRAWLINE: ;A0 = addr of box info, line X1Y1 in D4.L and X2Y2 in D5.L
  150.     MOVEM.L  D0-D5/A0-A5,-(SP)
  151.     MOVE.L   A0,A3              ;save addr of box info in A3
  152.     MOVE.L   LN_AVARS,A0        ;get addr of Line_A variables
  153.     ADDA.L   #24,A0             ;add 24 for offset to those we use
  154.     MOVE.W   BOXLCOLR(A3),D0    ;get color of our box's line
  155.     MOVE.W   #3,D1              ;4 color planes are used (-1 for dbra)
  156.     MOVEQ.L  #0,D2              ;0 out holder
  157. DLLOOP:
  158.     MOVE.W   D0,D2              ;get color bits in d2
  159.     AND.W    #1,D2              ;eliminate all but bit 1 of color
  160.     MOVE.W   D2,(A0)+           ;store colour bit in Line_A plane info
  161.     ROR.W    #1,D0              ;shift colour bits one bit right
  162.     DBRA     D1,DLLOOP          ;and continue for all 4 color planes
  163.     MOVE.W   #-1,(A0)+          ;LstLine should always be -1
  164.     MOVE.W   BOXLPTRN(A3),(A0)+ ;put in our line pattern
  165.     MOVE.W   BOXLMODE(A3),(A0)+ ;put in our writing mode
  166.     MOVE.L   D4,(A0)+           ;put in our upper left col/row
  167.     MOVE.L   D5,(A0)+           ;put in our lower right col/row
  168.     DC.W     $A003              ;draw the line - "Make it so!"
  169.     MOVEM.L  (SP)+,D0-D5/A0-A5
  170.     RTS
  171. ;---------------------------------------------------------------------
  172. FILL_BOX: ;A0= addr of box variables
  173.     MOVEM.L  D0-D5/A0-A5,-(SP)
  174.     MOVE.L   A0,A3              ;save addr of or box info
  175.     MOVE.L   LN_AVARS,A0        ;get addr of LIne_a variables
  176.     MOVE.L   A0,A2              ;save a copy of this addr
  177.     ADDA.L   #24,A0             ;move to the variables we'll use here
  178.     MOVE.W   BOXFCOLR(A3),D0    ;get box color
  179.     MOVE.W   #3,D1              ;assume we have up to 4 planes (-1)
  180.     MOVEQ.L  #0,D2              ;clear out our holder
  181. FLLOOP:
  182.     MOVE.W   D0,D2              ;copy bit pattern of colour
  183.     AND.W    #1,D2              ;keep the first bit only
  184.     MOVE.W   D2,(A0)+           ;store it in Line_A bit plane info
  185.     ROR.W    #1,D0              ;shift color 1 bit to right
  186.     DBRA     D1,FLLOOP          ;and repeat for all four planes
  187.     ADDQ.L   #4,A0              ;move past unwanted Line_A info
  188.     MOVE.W   BOXFMODE(A3),(A0)+ ;set the box writing mode
  189.     MOVE.L   BOX_X1(A3),D0      ;get the upper left corner col/row
  190.     ADD.L    #$00010001,D0      ;add 1 so that box is inside lines
  191.     MOVE.L   D0,(A0)+           ;set the upper left corner
  192.     MOVE.L   BOX_X2(A3),D0      ;do the same for lower right corner
  193.     SUB.L    #$00010001,D0      ;except we sub 1 from col and row
  194.     MOVE.L   D0,(A0)+
  195.     MOVE.L   BOXFFILL(A3),(A0)+ ;set addr of fill pattern to use
  196.     MOVE.W   #3,(A0)+           ;num of lines in fill pattern (- 1)
  197.     ADDQ.L   #2,A0              ;skip a portion of Line_A info
  198.     MOVE.W   #1,(A0)+           ;we want "clipping" to be in effect
  199.     MOVE.L   #0,(A0)+           ;use the upper left corner of screen
  200.     MOVE.W   -12(A2),(A0)+      ;and the lower right corner of screen
  201.     MOVE.W   -4(A2),(A0)        ; "
  202.     DC.W     $A005              ;draw the filled box on the screen
  203.     MOVEM.L  (SP)+,D0-D5/A0-A5
  204.     RTS
  205. ;---------------------------------------------------------------------
  206. TEXTBLIT: ;A0 = addr of null terminated string info
  207. ; Format: X,Y,Font_Number,Enlarge?,Style,Color_Of_Text,Background_Color
  208. ;         Write_Mode,String+0
  209.     MOVEM.L  D0-D3/A0-A3,-(SP)
  210.     MOVE.L   A0,A3              ;save copy of string info addr
  211.     MOVE.L   LN_AVARS,A0        ;get addr of Line_A variables
  212.     MOVE.L   LN_AFONT,A2        ;get addr of font table
  213.     MOVE.L   (A3)+,76(A0)       ;set col and row of string
  214.     MOVE.W   (A3)+,D1           ;get the font number we wish to use
  215. ; 0 = low rez font, 1 = medium rez font, 2 = high rez font
  216.     MOVE.W   (A3)+,66(A0)       ;set enlargement (0 = none, -1 = yes)
  217.     MOVE.W   #1,68(A0)          ;set boolean "use enlargment" to true
  218.     MOVE.W   #1,70(A0)          ;set "monospaced font data" to true
  219.     MOVE.W   (A3)+,90(A0)       ;set style of text to use
  220. ;0= normalstyle, bits:  0= bold, 1=lightened, 2= italics, 4= outlined
  221.     MOVE.W   #$5555,92(A0)      ;mask for lightened/shaded text
  222.     MOVE.W   64(A2),94(A0)      ;use systems own skewing mask
  223.     MOVE.W   #1,96(A0)          ;"weight" for bold/thicken (works best)
  224.     MOVE.W   56(A2),98(A0)      ;use systems own info for right offset
  225.     MOVE.W   56(A2),100(A0)     ; ditto for left offset in italics
  226.     MOVE.W   #1,102(A0)         ;set "scaling" flag to true
  227.     MOVE.W   #0,104(A0)         ;set angle of rotation to 0 (none)
  228. ;$384 = 90 degrees, $708 = 180, $A8C = 270 degrees of rotation
  229.     MOVE.W   (A3)+,106(A0)      ;set text color
  230.     MOVE.L   #TBLTBUFF,108(A0)  ;set addr of special effect buffer
  231.     MOVE.W   #$80,112(A0)       ;set offset to enlargement buffer
  232.     MOVE.W   (A3)+,114(A0)      ;set text background color
  233.     MOVE.W   (A3)+,36(A0)       ;set the writing mode for our text
  234.     MOVE.W   #1,54(A0)          ;set "clipping" to true
  235.     MOVE.L   #0,56(A0)          ;set upper left xy of screen
  236.     MOVE.W   -12(A0),D0         ;get lower right corner of screen:
  237.     SUBQ.W   #1,D0              ;-1
  238.     MOVE.W   D0,60(A0)          ;set it
  239.     MOVE.W   -4(A0),D0          ;  ditto
  240.     SUBQ.W   #1,D0
  241.     MOVE.W   D0,62(A0)
  242.     LSL.W    #2,D1              ;multiply font requested by 4
  243.     MOVE.L   (A2,D1),A2         ;get addr of that font
  244.     MOVE.L   76(A2),84(A0)      ;set addr of the font
  245.     MOVE.W   80(A2),88(A0)      ;set the width of the font
  246.     MOVE.W   82(A2),82(A0)      ;set the char height of the font
  247.     MOVE.L   72(A2),A1          ;get addr of font data for use below
  248. TBT_LOOP: ;here is the loop that outputs the zero terminated string:
  249.     MOVEQ.L  #0,D0              ;clear our char holder
  250.     MOVE.B   (A3)+,D0           ;get a char from string
  251.     BEQ      END_TBLT           ;if zero then we end
  252.     SUB.W    36(A2),D0          ;subtract char offset from char
  253.     LSL.W    #1,D0              ;multiply this by 2
  254.     MOVE.W   (A1,D0.W),72(A0)   ;set source of chars top
  255.     MOVE.W   #0,74(A0)          ;set source of chars 1st line
  256.     ADDQ.W   #2,D0              ;add 2 bytes to D0 for next char
  257.     MOVE.W   (A1,D0.W),D0       ;get next char offset
  258.     SUB.W    72(A0),D0          ;sub the last char from it
  259.     MOVE.W   D0,80(A0)          ;set this as the char's width
  260.     MOVE.W   #$8000,64(A0)      ;always set this before each $A008 call
  261.     MOVEM.L  D0-D3/A0-A3,-(SP)  ;save registers destoyed by call
  262.     DC.W     $A008              ;call the textblit routine - make it so
  263.     MOVEM.L  (SP)+,D0-D3/A0-A3  ;restore registers
  264.     BRA      TBT_LOOP           ;and go back to top of text output loop
  265. END_TBLT:
  266.     MOVEM.L  (SP)+,D0-D3/A0-A3
  267.     RTS
  268. ;---------------------------------------------------------------------
  269. MAKE_BOX: ;A0 = addr of box - creates a filled box & outlines it.
  270.     MOVEM.L  D4/D5,-(SP)
  271.     BSR      FILL_BOX           ;first fill the box, then
  272.     MOVE.L   BOX_X1(A0),D4      ;put upper left col/row in D4
  273.     MOVE.L   BOX_X2(A0),D5      ;put lower right col/row in D5
  274.     MOVE.W   D4,D5              ;put upper left row in D5
  275.     BSR      DRAWLINE           ;DO TOP LINE
  276.     MOVE.W   BOX_X1(A0),D5      ;put upper left col in D5
  277.     SWAP     D5                 ;move it to high word
  278.     MOVE.W   BOX_Y2(A0),D5      ;get lower right row in low word
  279.     BSR      DRAWLINE           ;DO LEFT SIDE
  280.     MOVE.W   D5,D4              ;put lower right row in D4
  281.     MOVE.L   BOX_X2(A0),D5      ;put lower right col/row in D5
  282.     BSR      DRAWLINE           ;DO BOTTOM LINE
  283.     MOVE.L   BOX_X2(A0),D4      ;put lower right col/row in D4
  284.     MOVE.W   BOX_Y1(A0),D4      ;put upper left row in D4
  285.     BSR      DRAWLINE           ;DO RIGHT SIDE
  286.     MOVEM.L  (SP)+,D4/D5
  287.     RTS
  288. ;---------------------------------------------------------------------
  289. DO_BOXES: ;uses Make_Box to draw all boxes in our data table listing
  290.     MOVEM.L  D0-D3/A0-A3,-(SP)
  291.     LEA      THEBOXES,A1        ;get addr of the boxes
  292.     MOVE.W   (A1)+,D1           ;get number of boxes to do
  293. SHOWBOXS:
  294.     MOVE.L   (A1)+,A0           ;get addr of box
  295.     BSR      MAKE_BOX           ;make it so
  296.     CMP.W    #2,D1              ;we don't want to fool with status box
  297.     BEQ      NOTTHIS1
  298.     MOVE.W   #MAKE_EOR,BOXFMODE(A0) ;set BOX FILL write mode to E_OR
  299. NOTTHIS1:
  300.     ADDQ.L   #4,A1              ;move past routine associted with box
  301.     DBRA     D1,SHOWBOXS        ;and do (show) all boxes
  302.     MOVEM.L  (SP)+,D0-D3/A0-A3
  303.     RTS
  304. ;---------------------------------------------------------------------
  305. DO_TEXT: ;writes all the text we need using our data table info.
  306.     MOVEM.L  D0-D3/A0-A3,-(SP)
  307.     LEA      THE_TEXT,A1        ;get addr of text table
  308.     MOVE.W   (A1)+,D1           ;get number of text items to show
  309. SHOWTEXT:
  310.     MOVE.L   (A1)+,A0           ;get addr of text
  311.     BSR      TEXTBLIT           ;show it
  312.     DBRA     D1,SHOWTEXT        ;and do all others
  313.     MOVEM.L  (SP)+,D0-D3/A0-A3
  314.     RTS
  315. ;---------------------------------------------------------------------
  316. CLR_SCRN: ;VT-52 routine to clear the screen
  317.     MOVEM.L  D0-D2/A0-A2,-(SP)
  318.     MOVE.W   #27,-(SP)         ; output ESC
  319.     MOVE.W   #2,-(SP)
  320.     MOVE.W   #3,-(SP)
  321.     TRAP     #13
  322.     ADDQ.L   #6,SP
  323.     MOVE.W   #69,-(SP)         ; output "E"
  324.     MOVE.W   #2,-(SP)
  325.     MOVE.W   #3,-(SP)
  326.     TRAP     #13
  327.     ADDQ.L   #6,SP
  328.     MOVEM.L  (SP)+,D0-D2/A0-A2
  329.     RTS
  330. ;---------------------------------------------------------------------
  331. CURS_ON: ;VT-52 routine to turn on the text cursor
  332.     MOVEM.L  D0-D4/A0-A4,-(SP)
  333.     MOVE.W   #27,-(SP)         ; output ESC
  334.     MOVE.W   #2,-(SP)
  335.     MOVE.W   #3,-(SP)
  336.     TRAP     #13
  337.     ADDQ.L   #6,SP
  338.     MOVE.W   #101,-(SP)         ; output "e"
  339.     MOVE.W   #2,-(SP)
  340.     MOVE.W   #3,-(SP)
  341.     TRAP     #13
  342.     ADDQ.L   #6,SP
  343.     MOVEM.L  (SP)+,D0-D4/A0-A4
  344.     RTS
  345. ;---------------------------------------------------------------------
  346. CURS_OFF: ;VT-52 routine to turn off the text cursor
  347.     MOVEM.L  D0-D4/A0-A4,-(SP)
  348.     MOVE.W   #27,-(SP)         ; output ESC
  349.     MOVE.W   #2,-(SP)
  350.     MOVE.W   #3,-(SP)
  351.     TRAP     #13
  352.     ADDQ.L   #6,SP
  353.     MOVE.W   #102,-(SP)         ; output "f"
  354.     MOVE.W   #2,-(SP)
  355.     MOVE.W   #3,-(SP)
  356.     TRAP     #13
  357.     ADDQ.L   #6,SP
  358.     MOVEM.L  (SP)+,D0-D4/A0-A4
  359.     RTS
  360. ;---------------------------------------------------------------------
  361. CHK_KBD: ; BConStat #1, D0 = 0 if no keys are in keyboard buffer
  362.     MOVEM.L  D1/D2/A0-A2,-(SP)
  363.     MOVE.W   #2,-(SP)
  364.     MOVE.W   #1,-(SP)
  365.     TRAP     #13
  366.     ADDQ.L   #4,SP
  367.     MOVEM.L  (SP)+,D1/D2/A0-A2
  368.     RTS
  369. ;---------------------------------------------------------------------
  370. GET_KEY: ; BConStat #2, D0 = key pressed
  371.     MOVEM.L  D1/D2/A0-A2,-(SP)
  372.     MOVE.W   #2,-(SP)
  373.     MOVE.W   #2,-(SP)
  374.     TRAP     #13
  375.     ADDQ.L   #4,SP
  376.     MOVEM.L  (SP)+,D1/D2/A0-A2
  377.     RTS
  378. ;---------------------------------------------------------------------
  379. MOUSBUTN: ;puts mouse button status in D0.W
  380. ;Thanks to STARFALL [Alan] (on GENIE, Wed Jul 24,1991) for offsets
  381.     MOVE.L   A0,-(SP)           ;(CAUTION!  This seems to work now...)
  382.     MOVE.L   LN_AVARS,A0        ;(...but it may not work with all TOS)
  383.     MOVE.W   -$254(A0),D0       ;(..versions.  VDI must then be used.)
  384.     MOVE.L   (SP)+,A0           ;(...... yuch! -C.H.)
  385.     RTS
  386. ;---------------------------------------------------------------------
  387. MOUS_XY: ; puts mouse cursor xy in D0.L
  388. ;Thanks to STARFALL [Alan] (on GENIE, Wed Jul 24,1991) for offsets
  389.     MOVE.L   A0,-(SP)           ;(CAUTION!  This seems to work now...)
  390.     MOVE.L   LN_AVARS,A0        ;(...but it may not work with all TOS)
  391.     MOVE.L   -$25A(A0),D0       ;(..versions.  VDI must then be used.)
  392.     MOVE.L   (SP)+,A0           ;(...... yuch! -C.H.)
  393.     RTS
  394. ;---------------------------------------------------------------------
  395. MOUS_ON: ;shows the mouse cursor - regardless of # of hide calls!
  396.     MOVEM.L  D0-D7/A0-A6,-(SP)
  397.     MOVE.L   LN_AVARS,A0        ;get addr of Line_A variables
  398.     MOVE.L   8(A0),A0           ;get addr of the IntIn array
  399.     CLR.W    (A0)               ;clear the number of "hide" calls
  400.     DC.W     $A009              ;show our mouse cursor
  401.     MOVEM.L  (SP)+,D0-D7/A0-A6
  402.     RTS
  403. ;---------------------------------------------------------------------
  404. MOUS_OFF: ;hides the mouse cursor
  405.     MOVEM.L  D0-D7/A0-A6,-(SP)
  406.     DC.W     $A00A              ;each call to this increments "hide"
  407.     MOVEM.L  (SP)+,D0-D7/A0-A6  ;          (see above)
  408.     RTS
  409. ;---------------------------------------------------------------------
  410. E_MULT: ; Puts char in D0.L, Mouse button in D1.W, Mouse XY in D2.L
  411. ; This is my "poor man's" version of GEM's Event_Multi - I hate Gem!
  412.     MOVEQ.L  #0,D0              ;clear char holder
  413.     MOVE.L   D0,D1              ; and mouse button holder
  414.     MOVE.L   D0,D2              ; and mouse XY holder
  415. EMULT1:
  416.     BSR      CHK_KBD            ;did user press a key?
  417.     TST.W    D0                 ;well?
  418.     BEQ      EMULT2             ;if not, then check mouse
  419.     BSR      GET_KEY            ;else get the key the user pressed
  420.     BRA      END_MULT           ;and leave
  421. EMULT2:
  422.     BSR      MOUSBUTN           ;did user press a mouse button?
  423.     TST.W    D0                 ;well?
  424.     BEQ      EMULT1             ;if not then go back to top of loop
  425.     EXG.L    D1,D0              ;else swap d0 and d1
  426.     BSR      MOUS_XY            ;and get the mouse XY
  427.     EXG.L    D0,D2              ;and put it in D2
  428. END_MULT:
  429.     RTS
  430. ;---------------------------------------------------------------------
  431. CLR_KBD: ;clears keyboard buffer of all key presses.
  432.     MOVEQ.L  #0,D0              ;clear our keypressed value
  433.     BSR      CHK_KBD            ;is there a key value in the buffer?
  434.     TST.W    D0
  435.     BEQ      KBD_CLR            ;if not, then we're OK
  436.     BSR      GET_KEY            ;else get the key from the buffer
  437.     BRA      CLR_KBD            ;and repeat till all chars are gone
  438. KBD_CLR:
  439.     RTS
  440. ;---------------------------------------------------------------------
  441. CLR_MOUS: ;waits till you release the mouse buttons
  442.     BSR      MOUSBUTN           ;get the mouse button value
  443.     TST.W    D0                 ;was a mouse button pressed?
  444.     BNE      CLR_MOUS           ;if so, then repeat till not
  445.     RTS
  446. ;---------------------------------------------------------------------
  447. F_FORMAT: ;formats one track - non-skewed
  448.     MOVEM.L  D1-D4/A0-A4,-(SP)
  449.     MOVE.W   #$E5E5,-(SP)       ;virgin data
  450.     MOVE.L   #$87654321,-(SP)   ;magic "valid atari disk" value
  451.     MOVE.W   #1,-(SP)           ;interleave value - normal value
  452.     MOVE.W   SIDE2DO,-(SP)      ;side
  453.     MOVE.W   TRAK2DO,-(SP)      ;track
  454.     MOVE.W   #10,-(SP)          ;sectors per track
  455.     MOVE.W   DRIVE,-(SP)        ;0 = drive A (1 would = drive B)
  456.     CLR.L    -(SP)
  457.     PEA      BUFFER             ;must be @ 1024 bytes long per track
  458.     MOVE.W   #10,-(SP)          ;XBIOS Floppy Format
  459.     TRAP     #14
  460.     LEA      26(SP),SP
  461.     MOVEM.L  (SP)+,D1-D4/A0-A4
  462.     RTS
  463. ;---------------------------------------------------------------------
  464. FLOPWRIT: ;writes data from a buffer to designated sectors.
  465.     MOVEM.L  D1-D4/A0-A4,-(SP)
  466.     MOVE.W   SEC2WRIT,-(SP)     ;sectors to write
  467.     MOVE.W   SIDE2DO,-(SP)      ;side to write
  468.     MOVE.W   TRAK2DO,-(SP)      ;track to write
  469.     MOVE.W   #1,-(SP)           ;starting sector should always be 1
  470.     MOVE.W   DRIVE,-(SP)        ;use designated drive
  471.     CLR.L    -(SP)              ;filler
  472.     PEA      BUFFER             ;use info in the buffer
  473.     MOVE.W   #9,-(SP)           ;XBIOS Floppy Write
  474.     TRAP     #14
  475.     LEA      20(SP),SP
  476.     MOVEM.L  (SP)+,D1-D4/A0-A4
  477.     RTS
  478. ;---------------------------------------------------------------------
  479. PROTO: ;puts Atari format disk boot sector data in our buffer.
  480.     MOVEM.L  D1-D4/A0-A4,-(SP)
  481.     MOVE.W   #0,-(SP)           ;boot sector should NOT be executable
  482.     MOVE.W   SIDES,D1           ;get # of sides user wants to format
  483.     ADDQ.W   #2,D1              ;add 2 to get proper value
  484.     MOVE.W   D1,-(SP)           ;80 tracks: 2=single sided, 3 = double
  485.     MOVE.L   #$01234567,-(SP)   ;create a random serial number
  486.     PEA      BUFFER             ;512 byte buffer is all we need
  487.     MOVE.W   #18,-(SP)          ;XBIOS protoboot
  488.     TRAP     #14
  489.     LEA      14(SP),SP
  490.     MOVEM.L  (SP)+,D1-D4/A0-A4
  491.     RTS
  492. ;---------------------------------------------------------------------
  493. FORMAT:  ;this carries out all the neccessary tasks to format a disk:
  494.     MOVEM.L  D1-D4/A0-A4,-(SP)
  495.     LEA      WORKING,A0         ;show that we're busy
  496.     BSR      TEXTBLIT
  497.  
  498.     BSR      CLIK_OFF           ;turn off the key click
  499.  
  500.     MOVE.W   #0,ERROR           ;assume all is ok - no errors
  501.  
  502. ; 1. format all tracks on sides 1 (and 2 ?) using XBIOS #10
  503.     MOVE.W   #0,SIDE2DO         ;start with side 0
  504.     MOVE.W   #0,TRAK2DO         ;and start with track 0
  505.  
  506. FRMTLOOP:
  507.     BSR      DOMUSIC            ;keep our music playing
  508.     BSR      F_FORMAT           ;do side 0
  509.     TST.L    D0                 ;did an error occur?
  510.     BMI      LEAVE              ;if so, get out
  511.  
  512.     TST.W    SIDES              ;see how many sides user has (wants)
  513.     BEQ      JUST_1             ;if 0 then user has just 1 side
  514.     MOVE.W   #1,SIDE2DO         ;else change to side 1
  515.     BSR      F_FORMAT           ;do side 1
  516.     TST.L    D0                 ;see if error occurred
  517.     BMI      LEAVE              ;and leave if it did
  518.     MOVE.W   #0,SIDE2DO         ;change back to side 0
  519.  
  520. JUST_1:
  521.  
  522.     LEA      STATLINE,A0        ;let's set up our status line info:
  523.     MOVE.L   BOX_X1(A0),D4      ;col
  524.     MOVE.L   BOX_X2(A0),D5      ;row
  525.     BSR      DRAWLINE           ;now draw our format status line
  526.     ADD.W    #1,BOX_X1(A0)      ;increment our status line columns:
  527.     ADD.W    #1,BOX_X2(A0)
  528.  
  529.     ADDQ.W   #1,TRAK2DO         ;move to next track
  530.     MOVE.W   TRAK2DO,D6         ;get the tracks we've done
  531.     MOVE.W   TRACKS,D7          ;and the total number we want to do
  532.     CMP.W    D6,D7              ;have we done all our tracks?
  533.     BNE      FRMTLOOP           ;if not then continue to format
  534.  
  535. ; 2. zero out the first two tracks on each side for FAT and DIR
  536. CLR_TRAK:
  537.     LEA      BUFFER,A0          ;get addr of our track buffer
  538.     MOVEQ.L  #0,D0              ;we'll write 4 zero bytes at a time
  539.     MOVE.W   #2559,D1           ;and fill the track buffer with 0's
  540. CLR_LOOP:
  541.     MOVE.L   D0,(A0)+
  542.     DBRA     D1,CLR_LOOP
  543.  
  544. ; (Now we must write these zeros to tracks 0 and 1 [on both sides])
  545. ; (This will zero out the File Allocation Tables and ...)
  546. ; (... the DIRectory listings for us.)
  547.     MOVE.W   #10,SEC2WRIT       ;sectors to write
  548.     MOVE.W   #0,SIDE2DO         ;start with side 0
  549.     MOVE.W   #0,TRAK2DO         ;and track 0
  550. WRITZERO:
  551.     BSR      FLOPWRIT           ;write zeros to one whole track
  552.     TST.L    D0                 ;did an error occur?
  553.     BMI      LEAVE              ;if so, bail out quick
  554.     TST.W    SIDES              ;see if user has more than 1 side
  555.     BEQ      ONLY_1             ;if 0 then user has just 1 side
  556.     MOVE.W   #1,SIDE2DO         ;do the other side
  557.     BSR      FLOPWRIT
  558.     TST.L    D0
  559.     BMI      LEAVE
  560.     MOVE.W   #0,SIDE2DO         ;go back to side 0
  561. ONLY_1:
  562.     ADDQ.W   #1,TRAK2DO         ;and move to the next track
  563.     CMP.W    #2,TRAK2DO
  564.     BNE      WRITZERO           ;make sure we ony do this to 2 tracks
  565.  
  566. ; 3. use XBIOS #18 to create a protoboot sector
  567.     BSR      PROTO              ;create the protoboot sector in buffer
  568.     TST.L    D0                 ;did we have an error?
  569.     BMI      LEAVE              ;if so, leave
  570.     LEA      BUFFER,A0          ;get addr of the protoboot sector
  571.  
  572. ; 4. we must alter the boot sector in the buffer if we are to use
  573. ;   anything over 9 sectors per track or 80 tracks per disk:
  574. ;   Here is how the info in the boot sector block is set up:
  575. ;
  576. ;    Offset in Bytes:                Description of info:
  577. ;
  578. ;            0                  Branch to boot code (if any)
  579. ;            2                  reserved for Operating Environment
  580. ;            8                  24 bit volume serial number
  581. ;            11                 Number of bytes per sector
  582. ;            13                 number of sectors per cluster
  583. ;            14                 number of reserved sectors
  584. ;            16                 # of File Allocation Tables
  585. ;            17                 number of directory entries
  586. ; Modified:  19                 total number of sectors on disk
  587. ;    "                          !low byte of word 1st then high byte!
  588. ;            21                 media descriptor - unused -
  589. ;            22                 number of sectors per FAT
  590. ; Modified:  24                 number of sectors per track
  591. ;            26                 number of sides to disk
  592. ;            28                 number of hidden sectors
  593. ;            30                 start of boot code (if any)
  594. ;                               !room for 480 bytes of code!
  595. ;            511                2 bytes used for checksum value
  596.  
  597.     MOVE.W   TRACKS,D0          ;get the number of tracks user wanted
  598.     MULU     #10,D0             ;times 10 sectors per track
  599.     MOVE.W   SIDES,D1           ;get # of sides the user has (0 or 1)
  600.     LSL.W    D1,D0              ;multiply it x 0 (or 2)
  601.  
  602.     MOVE.B   D0,19(A0)          ;use MS-DOS format to put in the info
  603.     LSR.W    #8,D0              ;shift high byte down to low byte
  604.     MOVE.B   D0,20(A0)          ;using MS-DOS format to put in info
  605.     MOVE.B   #10,24(A0)         ;and change to 10 sectors per track
  606.  
  607. ; 5. write this boot sector to disk at sector 1 track 0 side 0.
  608.     MOVE.W   #1,SEC2WRIT        ;sectors to write
  609.     MOVE.W   #0,SIDE2DO         ;side to write
  610.     MOVE.W   #0,TRAK2DO         ;track to write
  611.     BSR      FLOPWRIT           ;write the boot sector to disk
  612.     TST.L    D0                 ;did we have an error?
  613.     BMI      LEAVE              ;if so, leave
  614.     BRA      FMT_OK             ;else we get out successfully
  615. LEAVE:
  616.     MOVE.W   #1,ERROR
  617. FMT_OK:
  618.     LEA      SILENCE,A0         ;get addr of silence data
  619.     BSR      DO_SOUND           ;turn off the music
  620.  
  621.     LEA      STATCNST,A0        ;put StatLine data back as it was:
  622.     LEA      STATLINE,A1
  623.     MOVE.L   (A0)+,(A1)+
  624.     MOVE.L   (A0),(A1)
  625.  
  626.     LEA      THE_STAT,A0        ;remake the stat line box
  627.     BSR      MAKE_BOX
  628.     LEA      WAITING,A0         ;get addr of "Waiting" stat line text
  629.     TST.W    ERROR              ;did we have an error?
  630.     BEQ      NOERROR            ;if not then we're OK
  631.  
  632.     LEA      BOMBFALL,A0        ;else get addr of falling bomb sound
  633.     BSR      DO_SOUND           ;and play it
  634.     LEA      ANERROR,A0         ;and then get addr of "ERROR" text
  635. NOERROR:
  636.     BSR      TEXTBLIT           ;show the text
  637.     BSR      CLIK_ON            ;restore orig key click value
  638.     MOVEM.L  (SP)+,D1-D4/A0-A4
  639.     RTS
  640. ;---------------------------------------------------------------------
  641. RINGBELL:
  642.     MOVEM.L  D0-D3/A0-A3,-(SP)
  643.     MOVE.W   #7,-(SP)           ;sound bell note using ConOut
  644.     MOVE.W   #2,-(SP)
  645.     TRAP     #1
  646.     ADDQ.L   #4,SP
  647.     MOVEM.L  (SP)+,D0-D3/A0-A3
  648.     RTS
  649. ;---------------------------------------------------------------------
  650. ;-     The next 9 routines are what we use when selecting a box:     -
  651. ;---------------------------------------------------------------------
  652. SET_A:
  653.     BSR      MOUS_OFF           ;hide mouse
  654.     TST.W    DRIVE              ;see which drive we're using
  655.     BEQ      A_OK               ;if 0 then we need do nothing
  656.     LEA      THE_B,A0           ;else get addr of B drive box info
  657.     BSR      MAKE_BOX           ;and unhighlight the B drive
  658.     MOVE.W   #0,DRIVE           ;make Drive variable = to A drive
  659.     LEA      THE_A,A0           ;get addr of A drive box info
  660.     BSR      MAKE_BOX           ;and highlight it
  661. A_OK:
  662.     BSR      MOUS_ON            ;show the mouse again
  663.     BSR      CLR_MOUS           ;wait till user releases mouse button
  664.     RTS
  665. ;---------------------------------------------------------------------
  666. SET_B:
  667.     BSR      MOUS_OFF           ;see Set_A for what this does.
  668.     TST.W    DRIVE
  669.     BNE      B_OK
  670.     LEA      THE_A,A0
  671.     BSR      MAKE_BOX
  672.     MOVE.W   #1,DRIVE
  673.     LEA      THE_B,A0
  674.     BSR      MAKE_BOX
  675. B_OK:
  676.     BSR      MOUS_ON
  677.     BSR      CLR_MOUS           ;wait till user releases mouse button
  678.     RTS
  679. ;---------------------------------------------------------------------
  680. SET_1:
  681.     BSR      MOUS_OFF           ;see Set_A for how this works.
  682.     TST.W    SIDES
  683.     BEQ      S1_OK
  684.     LEA      THE_2,A0
  685.     BSR      MAKE_BOX
  686.     MOVE.W   #0,SIDES
  687.     LEA      THE_1,A0
  688.     BSR      MAKE_BOX
  689. S1_OK:
  690.     BSR      MOUS_ON
  691.     BSR      CLR_MOUS           ;wait till user releases mouse button
  692.     RTS
  693. ;---------------------------------------------------------------------
  694. SET_2:
  695.     BSR      MOUS_OFF           ;see Set_A
  696.     TST.W    SIDES
  697.     BNE      S2_OK
  698.     LEA      THE_1,A0
  699.     BSR      MAKE_BOX
  700.     MOVE.W   #1,SIDES
  701.     LEA      THE_2,A0
  702.     BSR      MAKE_BOX
  703. S2_OK:
  704.     BSR      MOUS_ON
  705.     BSR      CLR_MOUS           ;wait till user releases mouse button
  706.     RTS
  707. ;---------------------------------------------------------------------
  708. SET_80:
  709.     BSR      MOUS_OFF           ;see Set_A
  710.     CMP.W    #80,TRACKS
  711.     BEQ      T80_OK
  712.     LEA      THE_82,A0
  713.     BSR      MAKE_BOX
  714.     MOVE.W   #80,TRACKS
  715.     LEA      THE_80,A0
  716.     BSR      MAKE_BOX
  717. T80_OK:
  718.     BSR      MOUS_ON
  719.     BSR      CLR_MOUS           ;wait till user releases mouse button
  720.     RTS
  721. ;---------------------------------------------------------------------
  722. SET_82:
  723.     BSR      MOUS_OFF           ;see Set_A
  724.     CMP.W    #82,TRACKS
  725.     BEQ      T82_OK
  726.     LEA      THE_80,A0
  727.     BSR      MAKE_BOX
  728.     MOVE.W   #82,TRACKS
  729.     LEA      THE_82,A0
  730.     BSR      MAKE_BOX
  731. T82_OK:
  732.     BSR      MOUS_ON
  733.     BSR      CLR_MOUS           ;wait till user releases mouse button
  734.     RTS
  735. ;---------------------------------------------------------------------
  736. DOFORMAT:
  737.     BSR      MOUS_OFF           ;hide mouse
  738.     LEA      THE_FMT,A0         ;highlight format box
  739.     BSR      MAKE_BOX
  740.     BSR      FORMAT             ;format the disk
  741.     LEA      THE_FMT,A0
  742.     BSR      MAKE_BOX           ;unhighlight format box
  743.     BSR      MOUS_ON            ;show mouse again
  744.     BSR      CLR_MOUS           ;wait till user releases mouse button
  745.     RTS
  746. ;---------------------------------------------------------------------
  747. SET_EXIT:
  748.     BSR      MOUS_OFF           ;hide mouse
  749.     LEA      THE_EXIT,A0        ;highlight exit box
  750.     BSR      MAKE_BOX           ;(really not much point in this)
  751.     MOVE.W   #1,EXITFLAG        ;set ExitFlag to true (1)
  752.     BSR      MOUS_ON            ;and show mouse again
  753.     BSR      CLR_MOUS           ;wait till user releases mouse button
  754.     RTS
  755. ;---------------------------------------------------------------------
  756. NOTHING:                        ;a do_nothing filler routine
  757.     RTS
  758. ;---------------------------------------------------------------------
  759. DEFAULTS: ;sets default boxes and variables
  760.     MOVE.W   #0,EXITFLAG        ;set ExitFlag to false (0)
  761.     MOVE.W   #0,ERROR           ;start with 0 errors
  762.     MOVE.W   #0,DRIVE           ;and make the A the default drive
  763.     LEA      THE_A,A0           ;highlight the A drive box
  764.     BSR      MAKE_BOX
  765.     MOVE.W   #1,SIDES           ;make 2 sides the default
  766.     LEA      THE_2,A0           ;highlight the default sides box
  767.     BSR      MAKE_BOX
  768.     MOVE.W   #82,TRACKS         ;set default tracks to 82
  769.     LEA      THE_82,A0          ;and highlight that box
  770.     BSR      MAKE_BOX
  771.     RTS
  772. ;---------------------------------------------------------------------
  773. CHKBOXES: ;this runs through our list of boxes after mouse button is
  774. ;   pressed to see if it's in a box - if it is, we jump to the address
  775. ;   of the routine for that box.
  776.     LEA      THEBOXES,A1        ;get addr of our table of boxes
  777.     MOVE.W   (A1)+,D7           ;get number of boxes (-1 for dbra)
  778.     MOVE.L   (A1),A0            ;get the big box addr from our table
  779.     CMP.W    BOX_Y1(A0),D2      ;is mouse left of the left side?
  780.     BCS      OUTOFBOX           ;if so, we're out of the box
  781.     CMP.W    BOX_Y2(A0),D2      ;is mouse right of the right side?
  782.     BHI      OUTOFBOX           ;if so, we're out of the box
  783.     SWAP     D2                 ;put col value in low word of D2
  784.     CMP.W    BOX_X1(A0),D2      ;is mouse to left of the left side?
  785.     BCS      OUTOFBOX           ;if so, we're out of the box
  786.     CMP.W    BOX_X2(A0),D2      ;is mouse to right of the right side?
  787.     BLS      CHKNEXTS           ;if NOT then we're ok so far
  788. OUTOFBOX:
  789.     BSR      RINGBELL           ;else we're outside main box - ring bell
  790.     RTS                         ;and return
  791. CHKLOOP:
  792.     MOVE.L   (A1),A0            ;get the box addr from our table
  793.     CMP.W    BOX_Y1(A0),D2      ;is mouse at or right of the left side
  794.     BCS      CHKNEXT            ;if not then check next box
  795.     CMP.W    BOX_Y2(A0),D2      ;is mouse at or left of the right side
  796.     BHI      CHKNEXT            ;if not then check next box
  797.     SWAP     D2
  798.     CMP.W    BOX_X1(A0),D2      ;is mouse at or right of the left side
  799.     BCS      CHKNEXTS           ;if not then check next box
  800.     CMP.W    BOX_X2(A0),D2      ;is mouse at or left of the right side
  801.     BHI      CHKNEXTS           ;if not then check next box
  802.     ADDQ.L   #4,A1              ;we're IN the box, so move to routine
  803.     MOVE.L   (A1),A0            ;get addr of routine in A0
  804.     JMP      (A0)               ;and jump to that addr
  805. CHKNEXTS:
  806.     SWAP     D2                 ;put col back in highword of D2
  807. CHKNEXT:
  808.     ADDQ.L   #8,A1              ;move to next box in table
  809.     DBRA     D7,CHKLOOP         ;until all are checked
  810.     RTS
  811. ;---------------------------------------------------------------------
  812. CLIK_OFF: ;a key click will kill our music - so we will turn it off:
  813.     MOVEM.L  D0-D4/A0-A4,-(SP)
  814.     PEA      CLKOFF             ;use super_exec to execute this
  815.     MOVE.W   #38,-(SP)
  816.     TRAP     #14
  817.     ADDQ.L   #6,SP
  818.     MOVEM.L  (SP)+,D0-D4/A0-A4
  819.     RTS
  820. CLKOFF:
  821.     MOVE.W   D0,-(SP)
  822.     MOVE.B   $484,D0            ;get system conterm byte
  823.     MOVE.B   D0,CONTERM         ;save it so we can restore it later
  824.     AND.B    #8,D0              ;erase bits 0 to 2 to kill key clicks
  825.     MOVE.B   D0,$484            ;and put it back - make it so, # 1
  826.     MOVE.W   (SP)+,D0
  827.     RTS
  828. ;---------------------------------------------------------------------
  829. CLIK_ON: ;enable the key click sound after music is done:
  830.     MOVEM.L  D0-D4/A0-A4,-(SP)
  831.     PEA      CLKON              ;use super_exec to execute this
  832.     MOVE.W   #38,-(SP)
  833.     TRAP     #14
  834.     ADDQ.L   #6,SP
  835.     MOVEM.L  (SP)+,D0-D4/A0-A4
  836.     RTS
  837. CLKON:
  838.     MOVE.W   D0,-(SP)
  839.     MOVE.B   CONTERM,D0         ;get the conterm value we saved
  840.     MOVE.B   D0,$484            ;put it back as it was originally
  841.     MOVE.W   (SP)+,D0
  842.     RTS
  843. ;---------------------------------------------------------------------
  844. DOMUSIC: ;for continuous play of a song (USE IN A LOOP)
  845.     MOVEM.L  D0-D4/A0-A4,-(SP)
  846.     MOVE.L   #-1,-(SP)          ;let's see if there is any music
  847.     MOVE.W   #32,-(SP)          ;  or sound being processed:
  848.     TRAP     #14                ;D0 = 0 if there is no sound
  849.     ADDQ.L   #6,SP              ;otherwise the addr of sound table
  850.     TST.L    D0                 ;well?
  851.     BNE      SOUND_ON           ;if not 0 then sound is playing
  852.     PEA      MUSIC              ;put addr of our sound table on stack
  853.     MOVE.W   #32,-(SP)
  854.     TRAP     #14                ;play it again
  855.     ADDQ.L   #6,SP
  856. SOUND_ON:
  857.     MOVEM.L  (SP)+,D0-D4/A0-A4
  858.     RTS
  859. ;---------------------------------------------------------------------
  860. DO_SOUND: ;addr of sound/music in A0
  861.     MOVEM.L  D0-D4/A0-A4,-(SP)
  862.     MOVE.L   A0,-(SP)           ;put addr of our sound table on stack
  863.     MOVE.W   #32,-(SP)
  864.     TRAP     #14                ;kill all sounds
  865.     ADDQ.L   #6,SP
  866.     MOVEM.L  (SP)+,D0-D4/A0-A4
  867.     RTS
  868. ;---------------------------------------------------------------------
  869. GET_REZ: ;D0 will = 0 (low), or 1 (medium), or 2 (high rez)
  870.     MOVEM.L  D1-D4/A0-A4,-(SP)
  871.     MOVE.W   #4,-(SP)
  872.     TRAP     #14
  873.     ADDQ.L   #2,SP
  874.     MOVEM.L  (SP)+,D1-D4/A0-A4
  875.     RTS
  876. ;-------------------------------------------------------------------
  877.     DATA
  878. ; Unfortunately I will not take time to discuss the sound commands
  879. ; used below - maybe at another time and in another program. - C.H.
  880. BOMBFALL:
  881.  DC.B 0,0,1,1,2,0,3,0,4,0,5,0,6,0,7,254,8,7,9,0,10,0,11,0,12,0,13,0
  882.  DC.B 128,0,129,0,2,220,130,14
  883.  DC.B 1,0,6,10,7,199,8,16,9,16,10,16,11,0,12,80,13,0,130,120
  884.  DC.B 6,0,7,255,0,0,1,0,8,0,9,0,10,0,12,0,255,0
  885.  
  886. MUSIC: ;my simple rendition of the "Midnight Express" theme song:
  887. ; my apology to music buffs and the original authors of the tune/song.
  888. ; If you can find some public domain song data, you can put it here:
  889.   DC.B 0,$7B,1,$1,2,0,3,0,4,0,5,0,6,0,7,$F8,8,10,9,0,10,0,11,0,12,0,13,0
  890.   DC.B 130,16
  891.   DC.B 0,$A9,1,$1,7,$F8,8,10
  892.   DC.B 130,16
  893.   DC.B 0,$38,1,$2,7,$F8,8,10
  894.   DC.B 130,16
  895.   DC.B 0,$CB,1,$2,7,$F8,8,10
  896.   DC.B 130,16
  897.   DC.B 0,$F6,1,$2,7,$F8,8,10
  898.   DC.B 130,16
  899.   DC.B 0,$53,1,$3,7,$F8,8,10
  900.   DC.B 130,40
  901.  
  902.   DC.B 0,$7B,1,$1,7,$F8,8,10
  903.   DC.B 130,16
  904.   DC.B 0,$A9,1,$1,7,$F8,8,10
  905.   DC.B 130,16
  906.   DC.B 0,$38,1,$2,7,$F8,8,10
  907.   DC.B 130,16
  908.   DC.B 0,$CB,1,$2,7,$F8,8,10
  909.   DC.B 130,16
  910.   DC.B 0,$F6,1,$2,7,$F8,8,10
  911.   DC.B 130,16
  912.   DC.B 0,$53,1,$3,7,$F8,8,10
  913.   DC.B 130,16
  914.  
  915.   DC.B 0,$F6,1,$2,7,$F8,8,10
  916.   DC.B 130,16
  917.   DC.B 0,$CB,1,$2,7,$F8,8,10
  918.   DC.B 130,16
  919.   DC.B 0,$7D,1,$2,7,$F8,8,10
  920.   DC.B 130,16
  921.   DC.B 0,$38,1,$2,7,$F8,8,10
  922.   DC.B 130,16
  923.   DC.B 0,$F6,1,$2,7,$F8,8,10
  924.   DC.B 130,130
  925.  
  926.   DC.B 0,$7B,1,$1,7,$F8,8,10
  927.   DC.B 130,16
  928.   DC.B 0,$A9,1,$1,7,$F8,8,10
  929.   DC.B 130,16
  930.   DC.B 0,$38,1,$2,7,$F8,8,10
  931.   DC.B 130,16
  932.   DC.B 0,$CB,1,$2,7,$F8,8,10
  933.   DC.B 130,16
  934.   DC.B 0,$F6,1,$2,7,$F8,8,10
  935.   DC.B 130,16
  936.   DC.B 0,$53,1,$3,7,$F8,8,10
  937.   DC.B 130,40
  938.  
  939.   DC.B 0,$7B,1,$1,7,$F8,8,10
  940.   DC.B 130,16
  941.   DC.B 0,$A9,1,$1,7,$F8,8,10
  942.   DC.B 130,16
  943.   DC.B 0,$38,1,$2,7,$F8,8,10
  944.   DC.B 130,16
  945.   DC.B 0,$CB,1,$2,7,$F8,8,10
  946.   DC.B 130,16
  947.   DC.B 0,$F6,1,$2,7,$F8,8,10
  948.   DC.B 130,16
  949.   DC.B 0,$53,1,$3,7,$F8,8,10
  950.   DC.B 130,16
  951.  
  952.   DC.B 0,$F6,1,$2,7,$F8,8,10
  953.   DC.B 130,16
  954.   DC.B 0,$CB,1,$2,7,$F8,8,10
  955.   DC.B 130,16
  956.   DC.B 0,$7D,1,$2,7,$F8,8,10
  957.   DC.B 130,16
  958.   DC.B 0,$38,1,$2,7,$F8,8,10
  959.   DC.B 130,16
  960.   DC.B 0,$F6,1,$2,7,$F8,8,10
  961.   DC.B 130,130
  962. ;
  963.   DC.B 0,$A9,1,$1,7,$F8,8,10
  964.   DC.B 130,16
  965.   DC.B 0,$DD,1,$1,7,$F8,8,10
  966.   DC.B 130,16
  967.   DC.B 0,$18,1,$2,7,$F8,8,10
  968.   DC.B 130,16
  969.   DC.B 0,$CB,1,$2,7,$F8,8,10
  970.   DC.B 130,16
  971.   DC.B 0,$7D,1,$2,7,$F8,8,10
  972.   DC.B 130,16
  973.   DC.B 0,$38,1,$2,7,$F8,8,10
  974.   DC.B 130,16
  975.   DC.B 0,$18,1,$2,7,$F8,8,10
  976.   DC.B 130,16
  977.   DC.B 0,$DD,1,$1,7,$F8,8,10
  978.   DC.B 130,16
  979.   DC.B 0,$A9,1,$1,7,$F8,8,10
  980.   DC.B 130,50
  981.  
  982.   DC.B 0,$18,1,$2,7,$F8,8,10
  983.   DC.B 130,16
  984.   DC.B 0,$DD,1,$1,7,$F8,8,10
  985.   DC.B 130,16
  986.   DC.B 0,$A9,1,$1,7,$F8,8,10
  987.   DC.B 130,16
  988.   DC.B 0,$7B,1,$1,7,$F8,8,10
  989.   DC.B 130,16
  990.   DC.B 0,$65,1,$1,7,$F8,8,10
  991.   DC.B 130,16
  992.   DC.B 0,$3E,1,$1,7,$F8,8,10
  993.   DC.B 130,16
  994.   DC.B 0,$1C,1,$1,7,$F8,8,10
  995.   DC.B 130,16
  996.   DC.B 0,$A9,1,$1,7,$F8,8,10
  997.   DC.B 130,130
  998.  
  999.   DC.B 0,$1C,1,$1,7,$F8,8,10
  1000.   DC.B 130,16
  1001.   DC.B 0,$1C,1,$1,7,$F8,8,10
  1002.   DC.B 130,16
  1003.   DC.B 0,$3E,1,$1,7,$F8,8,10
  1004.   DC.B 130,16
  1005.   DC.B 0,$3E,1,$1,7,$F8,8,10
  1006.   DC.B 130,16
  1007.   DC.B 0,$65,1,$1,7,$F8,8,10
  1008.   DC.B 130,16
  1009.   DC.B 0,$1C,1,$1,7,$F8,8,10
  1010.   DC.B 130,32
  1011.  
  1012.   DC.B 0,$3E,1,$1,7,$F8,8,10
  1013.   DC.B 130,8
  1014.   DC.B 0,$3E,1,$1,7,$F8,8,10
  1015.   DC.B 130,130
  1016.  
  1017.   DC.B 0,$91,1,$1,7,$F8,8,10
  1018.   DC.B 130,16
  1019.   DC.B 0,$65,1,$1,7,$F8,8,10
  1020.   DC.B 130,16
  1021.   DC.B 0,$3E,1,$1,7,$F8,8,10
  1022.   DC.B 130,16
  1023.   DC.B 0,$1C,1,$1,7,$F8,8,10
  1024.   DC.B 130,16
  1025.   DC.B 0,$0C,1,$1,7,$F8,8,10
  1026.   DC.B 130,16
  1027.  
  1028.   DC.B 0,$1C,1,$1,2,$D4,3,0,7,$F8,8,10,9,10
  1029.   DC.B 130,8
  1030.   DC.B 0,$1C,1,$1,2,$C8,3,0,7,$F8,8,10,9,10
  1031.   DC.B 130,8
  1032.   DC.B 0,$1C,1,$1,2,$D4,3,0,7,$F8,8,10,9,10
  1033.   DC.B 130,8
  1034.   DC.B 0,$1C,1,$1,2,$EE,3,0,7,$F8,8,10,9,10
  1035.   DC.B 130,4
  1036.   DC.B 0,$1C,1,$1,2,$EE,3,0,7,$F8,8,10,9,10
  1037.   DC.B 130,4
  1038.   DC.B 0,$1C,1,$1,2,$D4,3,0,7,$F8,8,10,9,10
  1039.   DC.B 130,8
  1040.   DC.B 0,$1C,1,$1,2,$EE,3,0,7,$F8,8,10,9,10
  1041.   DC.B 130,10
  1042.   DC.B 0,$1C,1,$1,2,$D4,3,0,7,$F8,8,10,9,10
  1043.   DC.B 130,16
  1044.  
  1045.   DC.B 0,$1C,1,$1,7,$F8,8,10,9,10
  1046.   DC.B 130,8
  1047.   DC.B 0,$1C,1,$1,2,$D4,3,0,7,$F8,8,10,9,10
  1048.   DC.B 130,8
  1049.   DC.B 0,$1C,1,$1,2,$C8,3,0,7,$F8,8,10,9,10
  1050.   DC.B 130,8
  1051.   DC.B 0,$1C,1,$1,2,$D4,3,0,7,$F8,8,10,9,10
  1052.   DC.B 130,8
  1053.   DC.B 0,$1C,1,$1,2,$EE,3,0,7,$F8,8,10,9,10
  1054.   DC.B 130,4
  1055.   DC.B 0,$1C,1,$1,2,$EE,3,0,7,$F8,8,10,9,10
  1056.   DC.B 130,4
  1057.   DC.B 0,$1C,1,$1,2,$D4,3,0,7,$F8,8,10,9,10
  1058.   DC.B 130,80
  1059.  
  1060. SILENCE:
  1061.   DC.B 0,0,1,0,2,0,3,0,4,0,5,0,6,0,7,$FF,8,0,9,0,10,0,11,0,12,0,13,0
  1062.   DC.B 255,0 ;end all sounds
  1063.  
  1064. MOUSE_1: ;our new mouse shape/color data:
  1065. ;mouse's column and row for the hot_spot:
  1066.     DC.W     8,8
  1067. ;mouse mask color and shape color
  1068.     DC.W     2,15
  1069. ;mouse mask:
  1070.     DC.W     %1110000000000111
  1071.     DC.W     %1110000000000111
  1072.     DC.W     %0111000000001110
  1073.     DC.W     %0011100000011100
  1074.     DC.W     %0001110000111000
  1075.     DC.W     %0000111001110000
  1076.     DC.W     %0000011111100000
  1077.     DC.W     %0000001111000000
  1078.     DC.W     %0000001111000000
  1079.     DC.W     %0000011111100000
  1080.     DC.W     %0000111001110000
  1081.     DC.W     %0001110000111000
  1082.     DC.W     %0011100000011100
  1083.     DC.W     %0111000000001110
  1084.     DC.W     %1110000000000111
  1085.     DC.W     %1110000000000111
  1086. ;mouse shape
  1087.     DC.W     %0000000000000000
  1088.     DC.W     %0100000000000010
  1089.     DC.W     %0010000000000100
  1090.     DC.W     %0001000000001000
  1091.     DC.W     %0000100000010000
  1092.     DC.W     %0000010000100000
  1093.     DC.W     %0000001001000000
  1094.     DC.W     %0000000110000000
  1095.     DC.W     %0000000110000000
  1096.     DC.W     %0000001001000000
  1097.     DC.W     %0000010000100000
  1098.     DC.W     %0000100000010000
  1099.     DC.W     %0001000000001000
  1100.     DC.W     %0010000000000100
  1101.     DC.W     %0100000000000010
  1102.     DC.W     %0000000000000000
  1103.  
  1104. ;a few of the different types of fills you can use - create your own.
  1105. FILL_1:      DC.W $FFFF,$FFFF,$FFFF,$FFFF
  1106. FILL_2:      DC.W $5555,$5555,$5555,$5555
  1107. FILL_3:      DC.W $8888,$8888,$8888,$8888
  1108. FILL_4:      DC.W $FFFF,$5555,$FFFF,$5555
  1109. FILL_5:      DC.W $FFFF,$8888,$FFFF,$8888
  1110. FILL_6:      DC.W $FFFF,$0000,$FFFF,$0000
  1111. FILL_7:      DC.W $5555,$8888,$5555,$8888
  1112. FILL_8:      DC.W $5555,$0000,$5555,$0000
  1113. FILL_9:      DC.W $AAAA,$5555,$AAAA,$5555
  1114. FILL_10:     DC.W $8888,$4444,$2222,$1111
  1115.  
  1116. BOXFILLS:    DC.L FILL_1,FILL_2,FILL_3,FILL_4,FILL_5
  1117.              DC.L FILL_6,FILL_7,FILL_8,FILL_9,FILL_10
  1118.  
  1119. TITLE:
  1120. ; Format: X,Y,Font_Number,Enlarge?,Style,Color_Of_Text,Background_Color
  1121. ;         Write_Mode,String+0
  1122.     DC.W     260,32,1,0,0,15,0,JUST_OR
  1123.     DC.B     "Disk Formatter",0
  1124.     ALIGN
  1125. CREDIT:
  1126.     DC.W     273,40,0,0,0,15,0,JUST_OR
  1127.     DC.B     "By Clark A. Hay",0
  1128.     ALIGN
  1129. SHOW_A:
  1130.     DC.W     272,48,1,0,0,15,0,JUST_OR
  1131.     DC.B     "A",0
  1132.     ALIGN
  1133. SHOW_DRV:
  1134.     DC.W     296,48,1,0,0,15,0,JUST_OR
  1135.     DC.B     "Drive",0
  1136.     ALIGN
  1137. SHOW_B:
  1138.     DC.W     352,48,1,0,0,15,0,JUST_OR
  1139.     DC.B     "B",0
  1140.     ALIGN
  1141. SHOW_1:
  1142.     DC.W     272,62,1,0,0,15,0,JUST_OR
  1143.     DC.B     "1",0
  1144.     ALIGN
  1145. SHOW_SID:
  1146.     DC.W     296,62,1,0,0,15,0,JUST_OR
  1147.     DC.B     "Sides",0
  1148.     ALIGN
  1149. SHOW_2:
  1150.     DC.W     352,62,1,0,0,15,0,JUST_OR
  1151.     DC.B     "2",0
  1152.     ALIGN
  1153. HOW_MANY:
  1154.     DC.W     256,73,1,0,0,15,0,JUST_OR
  1155.     DC.B     "How Many Tracks",0
  1156.     ALIGN
  1157. SHOW_80:
  1158.     DC.W     280,85,1,0,0,15,0,JUST_OR
  1159.     DC.B     "80",0
  1160.     ALIGN
  1161. SHOW_82:
  1162.     DC.W     336,85,1,0,0,15,0,JUST_OR
  1163.     DC.B     "82",0
  1164.     ALIGN
  1165. STATUS:
  1166.     DC.W     264,97,1,0,0,15,0,JUST_OR
  1167.     DC.B     "Format Status",0
  1168.     ALIGN
  1169. WAITING:
  1170.     DC.W     289,108,1,0,0,15,0,JUST_OR
  1171.     DC.B     "Waiting",0
  1172.     ALIGN
  1173. SHOW_FMT:
  1174.     DC.W     264,121,1,0,0,15,0,JUST_OR
  1175.     DC.B     "Format",0
  1176.     ALIGN
  1177. SHOW_EXT:
  1178.     DC.W     336,121,1,0,0,15,0,JUST_OR
  1179.     DC.B     "Exit",0
  1180.     ALIGN
  1181.  
  1182. WORKING:
  1183.     DC.W     289,108,1,0,0,15,0,REPLACE
  1184.     DC.B     "Working",0
  1185.     ALIGN
  1186. ANERROR:
  1187.     DC.W     297,108,1,0,0,15,0,JUST_OR
  1188.     DC.B     "ERROR",0
  1189.     ALIGN
  1190.  
  1191. THE_TEXT:
  1192.     DC.W     14 ;number of text items (- 1) to display
  1193.     DC.L     TITLE,CREDIT,SHOW_A,SHOW_DRV,SHOW_B,SHOW_1,SHOW_SID,SHOW_2
  1194.     DC.L     HOW_MANY,SHOW_80,SHOW_82,STATUS,WAITING,SHOW_FMT,SHOW_EXT
  1195.  
  1196.  
  1197. ;Box Format: X1,Y1,X2,Y2,Fill_Color,Fill_Addr,Fill_Mode,Line_Color,
  1198. ;            Line_Pattern,Line_Draw_Mode
  1199. BIG_BOX:
  1200.     DC.W     252,30,379,132,2
  1201.     DC.L     FILL_3
  1202.     DC.W     REPLACE,15,$FFFF,REPLACE
  1203. THE_A:
  1204.     DC.W     268,46,283,56,0
  1205.     DC.L     FILL_1
  1206.     DC.W     REPLACE,15,$FFFF,REPLACE
  1207. THE_B:
  1208.     DC.W     348,46,363,56,0
  1209.     DC.L     FILL_1
  1210.     DC.W     REPLACE,15,$FFFF,REPLACE
  1211. THE_1:
  1212.     DC.W     268,60,283,70,0
  1213.     DC.L     FILL_1
  1214.     DC.W     REPLACE,15,$FFFF,REPLACE
  1215. THE_2:
  1216.     DC.W     348,60,363,70,0
  1217.     DC.L     FILL_1
  1218.     DC.W     REPLACE,15,$FFFF,REPLACE
  1219. THE_80:
  1220.     DC.W     276,83,299,93,0
  1221.     DC.L     FILL_1
  1222.     DC.W     REPLACE,15,$FFFF,REPLACE
  1223. THE_82:
  1224.     DC.W     332,83,355,93,0
  1225.     DC.L     FILL_1
  1226.     DC.W     REPLACE,15,$FFFF,REPLACE
  1227. THE_STAT:
  1228.     DC.W     274,106,358,116,0
  1229.     DC.L     FILL_1
  1230.     DC.W     REPLACE,15,$FFFF,REPLACE
  1231. THE_FMT:
  1232.     DC.W     260,119,316,129,0
  1233.     DC.L     FILL_1
  1234.     DC.W     REPLACE,15,$FFFF,REPLACE
  1235. THE_EXIT:
  1236.     DC.W     332,119,372,129,0
  1237.     DC.L     FILL_1
  1238.     DC.W     REPLACE,15,$FFFF,REPLACE
  1239.  
  1240. STATCNST:
  1241.     DC.W     275,107,275,115
  1242. STATLINE:
  1243.     DC.W     275,107,275,115,0
  1244.     DC.L     FILL_1
  1245.     DC.W     REPLACE,1,$FFFF,MAKE_EOR
  1246.  
  1247. THEBOXES:
  1248.     DC.W     9  ;number of boxes/routines -1 for dbra
  1249. ; addr of box_data & addr of routine to execute if mouse is in box
  1250.     DC.L     BIG_BOX,NOTHING
  1251.     DC.L     THE_A,SET_A
  1252.     DC.L     THE_B,SET_B
  1253.     DC.L     THE_1,SET_1
  1254.     DC.L     THE_2,SET_2
  1255.     DC.L     THE_80,SET_80
  1256.     DC.L     THE_82,SET_82
  1257.     DC.L     THE_STAT,NOTHING
  1258.     DC.L     THE_FMT,DOFORMAT
  1259.     DC.L     THE_EXIT,SET_EXIT
  1260. ;---------------------------------------------------------------------
  1261.     BSS
  1262.              DS.L 300           ;big enough stack for most programs
  1263. PRGSTACK:    DS.L 1             ;our stack starts here and goes up
  1264.              DS.L 10            ;just in case we undershoot the stack
  1265.  
  1266. DRIVE:       DS.W 1             ;the designated drive to format
  1267. TRACKS:      DS.W 1             ;number of tracks user wants to do
  1268. SIDES:       DS.W 1             ;number of sides the user has
  1269. TRAK2DO:     DS.W 1             ;track number to format
  1270. SIDE2DO:     DS.W 1             ;side of disk to format
  1271. SEC2WRIT:    DS.W 1             ;number of sectors to write
  1272. EXITFLAG:    DS.W 1             ;no exit if exit = 0
  1273. ERROR:       DS.W 1             ;no errors if error = 0
  1274. CONTERM:     DS.W 1             ;holder for original conterm vlue
  1275.  
  1276. LN_AVARS:    DS.L 1             ;holder for Line_A variables addr
  1277. LN_AFONT:    DS.L 1             ;holder for system Font Addr table
  1278. TBLTBUFF:    DS.B $1200         ;buffer used by TextBlit special effects
  1279.  
  1280. BUFFER:      DS.B 10*1024       ;disk formatting buffer
  1281.     END
  1282.  
  1283. ;that's all... Enjoy! - C.H.
  1284.